<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>服务评论列表</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<blockquote class="layui-elem-quote list_search">
    <div class="layui-inline">
        <a class="layui-btn layui-btn-danger batchDel"
           data-type="delCheckData"><i class="layui-icon">&#xe640;</i>批量删除</a>
    </div>
</blockquote>
<script type="text/html" id="sratus">
    <input type="checkbox" name="id" value="{{d.id}}" title="审核通过" lay-filter="lockStatus" {{ d.enterStatus == 1 ?'checked' : '' }}>
</script>
<script type="text/html" id="type">
    {{#  if(d.serverType == 1){ }}
    <span>商户</span>
    {{#  } else { }}
    <span>物业</span>
    {{#  } }}
</script>
<table id="dynamicList" lay-filter="dynamicList" class="layui-hidden"></table>
<script th:src="@{/src/layui.js}"></script>
<script>
    layui.use(['jquery','layer','laypage','laytpl','table','laydate','form'],function () {
        var $ = layui.jquery,
            layer = layui.layer,
            laypage = layui.laypage,
            laytpl = layui.laytpl,
            form = layui.form,
            table = layui.table,laydate = layui.laydate;
        table.render({
            elem:'#dynamicList',
            url:'/server/enterList',
            title:'入驻列表',
            cellMinWidth:80,
            page:true,
            limit:10,
            cols:[
                [
                    {type:'checkbox'},
                    {title:'ID',field:"id"},
                    {title:'服务菜单',field:'serverName'},
                    {title:'服务价格',field:'price',width:90},
                    {title:'入驻物业/商户',field:'account'},
                    {title:'入驻类型',field:'serverType',templet:'#type'},
                    {title:'审核时间',field:'enterTime'},
                    {title:'审核状态',field:'enterStatus',templet:'#sratus'},
                    {title:'审核人员',field:'auditor'}
                ]
            ],parseData:function(result){
                return {
                    code:result.code==200?0:result.code,
                    msg:result.message,
                    count:result.data.total,
                    data:result.data.list
                }
            }
        });
        //监听锁定事件
        form.on('checkbox(lockStatus)',function (data) {
            var id = data.elem.value;
            var status = data.elem.checked?1:0;
            $.ajax({
                url:'/server/checkStatus',
                data:{id:id,status:status},
                type:'put',
                dataType:'json',
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('更新成功',{icon:1,time:1000},function () {
                            table.reload('dynamicList',{});
                        })
                    }else{
                        layui.msg('更新失败',{icon:5})
                    }
                }
            })
        })



        //批量删除
        $('.batchDel').click(function () {
            //获取选中的数据
            var checkStatus = table.checkStatus('dynamicList');
            var data = checkStatus.data;
            if (data.length == 0){
                layer.msg("请选择服务数据",{icon:5});
                return ;
            }
            var ids = '';
            $.each(data,function (index , comment) {//遍历数组，取出动态id
                if (index == data.length - 1){
                    ids += comment.id;
                } else {
                    ids += comment.id + ',';
                }
            })
            $.ajax({
                url:'/server/batchDelEnter',
                type:'delete',
                data:{'ids':ids},//传id字符串到后端
                dataType:'json',
                success : function (result) {
                    if (result.code == 200){
                        layer.msg(result.message,{icon:1},function () {
                            location.reload();
                        })
                    }else {
                        layer.msg(result.message,{icon:5});
                    }
                }
            })

        })
    })
</script>

</body>
</html>